home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STPLT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.2 KB  |  46 lines

  1. #include <stdio.h>
  2. #include <graphics.h>
  3. /* Define array of colors using defined constants from
  4.  * graphics.h
  5.  */
  6.  int colors[] =
  7.     { EGA_BLACK, EGA_BLUE, EGA_GREEN, EGA_CYAN, EGA_RED,
  8.       EGA_MAGENTA, EGA_BROWN, EGA_LIGHTGRAY,
  9.       EGA_DARKGRAY, EGA_LIGHTBLUE, EGA_LIGHTGREEN,
  10.       EGA_LIGHTCYAN, EGA_LIGHTRED, EGA_LIGHTMAGENTA,
  11.       EGA_YELLOW, EGA_WHITE};
  12.  
  13. main()
  14. {
  15.    int graphdriver = DETECT, graphmode, i=0;
  16.  
  17. /* Detect and initialize graphics system */
  18.    initgraph(&graphdriver, &graphmode, "c:\\turboc");
  19.    if (graphdriver != EGA && graphdriver != VGA)
  20.    {
  21. /* Error setting mode */
  22.       closegraph();
  23.       printf("Not EGA/VGA hardware\n");
  24.       exit(0);
  25.    }
  26.    setcolor(1);
  27.    outtextxy(10,10, "Demonstrating setpalette");
  28. /* Loop through several colors for pixel
  29.  * values 0 and 1
  30.  */
  31.    outtextxy(10,20, "press any key to go on, 'q' to exit");
  32.    while(1)
  33.    {
  34.       if (getch() == 'q')
  35.       {
  36.    /* Reset graphics environment */
  37.      closegraph();
  38.      exit(0);
  39.       }
  40.    /* Alter pixel value 0 and 1 */
  41.      setpalette(0, colors[i%16]);
  42.      setpalette(1, colors[(i+2)%16]);
  43.    /* Select next color from array */
  44.      i++;
  45.    }
  46. }